﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Common
{
    public class XnaTextSprite : AutomatedSprite
    {
        public static SpriteFont CommonSpriteFont;//公共字体单例
        public string Text = string.Empty;
        public SpriteFont SpriteFont;
        public Vector2 Position;
        public Color Color =Color.White;

        public XnaTextSprite(string text,Vector2 position)
        {
            this.Text = text;
            this.Position = position;
            CommonSpriteFont = LoadCommonFont();
        }
        public void DrawString()
        {
            if (this.SpriteFont != null)
                SpriteBatch.DrawString(this.SpriteFont,this.Text,this.Position,this.Color);
            else
                SpriteBatch.DrawString(CommonSpriteFont, this.Text, this.Position, this.Color);
        }

        public SpriteFont LoadFont(string font)
        {
            if (this.SpriteFont == null)
                return Game.Content.Load<SpriteFont>(@"Fonts\"+font);
            else
                return this.SpriteFont;
        }
        /// <summary>
        /// 加载通用字体
        /// </summary>
        /// <returns></returns>
        public SpriteFont LoadCommonFont()
        {
            if (CommonSpriteFont == null)
                return Game.Content.Load<SpriteFont>(@"Fonts\SpriteFont1");
            else
                return CommonSpriteFont;
        }
    }
}
